package com.cskaoyan.order.biz.handler;

import com.cskaoyan.order.biz.context.CreateOrderContext;
import com.cskaoyan.order.biz.context.TransHandlerContext;
import com.cskaoyan.order.mq.delay.DelayOrderCannelProducer;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Description: 利用mq发送延迟取消订单消息
 **/
@Component
@Slf4j
public class SendMessageHandler extends AbstractTransHandler {
@Autowired
	DelayOrderCannelProducer delayOrderCannelProducer;

	@Override
	public boolean isAsync() {
		return false;
	}

	@Override
	public boolean handle(TransHandlerContext context) {
		//TODO 拿到orderid 发送延迟消息 producer
		//TODO context上下文对象
		// orderid 强转为了调用子类的调用方法
		CreateOrderContext createOrderContext = (CreateOrderContext) context;
		String orderId = createOrderContext.getOrderId();
		//TODO 调用一个方法。发送延迟消息
		boolean result = delayOrderCannelProducer.sendDelayOrderMessage(orderId);
		return result;
	}
}